package com.suxin.rule.abstrct;

import com.suxin.rule.dto.NationalityRuleDTO;
import com.suxin.rule.RuleConstant;
import com.suxin.rule.dto.RuleDTO;

/**
 * @author Tang
 * @classname NationalityRule
 * @description [  ]
 * @date 2022/1/9 19:14
 */
public class NationalityRule extends AbstractRule{

    @Override
    protected <T> T convert(RuleDTO ruleDTO) {
        NationalityRuleDTO nationalityRuleDTO = new NationalityRuleDTO();
        if (ruleDTO.getAddress().startsWith(RuleConstant.MATCH_NATIONALITY_START)) {
            nationalityRuleDTO.setNationality(RuleConstant.MATCH_NATIONALITY_START);
        }
        return (T)nationalityRuleDTO;
    }

    @Override
    protected <T> boolean executeRule(T t) {
        NationalityRuleDTO nationalityRuleDTO = (NationalityRuleDTO) t;
        return nationalityRuleDTO.getNationality().startsWith(RuleConstant.MATCH_NATIONALITY_START);
    }
}